﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using Gumini.JulaDB.Enums;

namespace Gumini.JulaDB.DataTypes
{
    public class VarcharDateType : DataType
    {
        public VarcharDateType()
            : base(JulaDbType.Varchar, DbType.String, typeof(string)) { }

        public override int Compare(object a, object b)
        {
            return string.Compare((string)a, (string)b, false);
        }

        protected override object ConvertCore(object source)
        {
            //return ((IFormattable)source.Value).ToString(null, CultureInfo.InvariantCulture);
            var convertible = source as IConvertible;
            return convertible.ToString(CultureInfo.InvariantCulture);
        }

        public override IEnumerable<string> Names
        {
            get { yield return "varchar"; }
        }

        public override IEnumerable<Type> SourceTypes
        {
            get { yield return typeof(string); }
        }

        public override string ToString()
        {
            return "VARCHAR";
        }
    }
}
